<!--
/*
 * Displays to the user the questions, choices, and answers available in the survey.
 * Also includes a button for generating graphs
 */
-->
<html>
<head>

<title></title>
</head>
<body>

<h2>
<?php
	//displays the survey title
	echo $title;
?>
</h2>

<?php
//define where to go when user wants to view the graphs
echo form_open('user/view_survey_graph'.'/'.$id.'/'.$survey_id.'/');

//a drop down box indicating the possible graphs to generate
echo "Select graph type: <select name = 'chart'>";
echo "<option value = 'bar'>Bar graph</option>";
echo "<option value = 'pie'>Pie graph</option>";
echo "</select>";

//a drop down box indicating the available separators
echo "&nbsp&nbspSeparator: <select name = 'separator'>";
echo "<option value = 'none' SELECTED>None</option>";
if ($gender_required)
{
	echo "<option value = 'gender'>Gender</option>";
}
if ($age_required)
{
	echo "<option value = 'age'>Age</option>";
}
echo "</select>";
echo "&nbsp&nbsp";

//button for generating the graphs
echo "<input type='submit' name='submit' value='Generate!'/>";

echo form_close();
?>

<?php
//displays the some statistics for the survey
echo "Number of invited respondents: " . $num_invitations. "<br>";
echo "Number of respondents who answered: " . $num_respondents . "<br><br>";
?>

<?php
//displays the category, questions, choices and answers gathered for the survey
//this is used when survey is defined to have question categories.
if($has_groups)
{
	$O = count($category);
	for($l = 0; $l < $O; $l++)
	{
		echo "<h3>".$category[$l]->category_name."</h3>";
		if (isset($questions[$l]))
		{
			$N = count($questions[$l]);
			for($i = 0; $i < $N; $i++)
			{
				//display the question
				echo "<br><strong><br><br>".$questions[$l][$i]->body."<br>&nbsp&nbsp&nbsp&nbsp".$text_label[$l][$i]."</strong><br>";
				
				//display the choices if there is any, and the answers for the question
				//also includes the narrative availble for the question
				if ($choice[$l][$i][0] != null)
				{
					$M = count($choice[$l][$i]);
					for($j = 0; $j < $M; $j++)
					{
						echo $choice[$l][$i][$j] . ": ". $answer[$l][$i][$j]. "<br>";
					}
					for($j = 0; $j < count($narrative[$l][$i]); $j++)
					{
						if($narrative[$l][$i][$j] == '') {
						}else {
							echo "&nbsp&nbsp&nbsp&nbsp".$narrative[$l][$i][$j]. "<br>";
						}
					}
				}else {
					$L = count($answer[$l][$i]);
					for($k = 0; $k < $L; $k++)
					{
						echo "&bull;".nl2br($answer[$l][$i][$k]) . "<br>";
						if($narrative[$l][$i][$k] == '') {
						}else {
							echo "&nbsp&nbsp&nbsp&nbsp".$narrative[$l][$i][$k]. "<br>";
						}
					}
				}
			}
		}
	}
//displays the questions, choices, and answers gathered for the survey.
//this is used when survey is defined to have no question categories.
}else {
	$N = count($questions);
	for($i = 0; $i < $N; $i++)
	{
		//display the question
		echo "<strong><br><br>".$questions[$i]->body."<br>&nbsp&nbsp&nbsp&nbsp".$text_label[$i]."</strong><br>";
		
		//display the choices if there is any, and the answers for the question
		//also includes the narrative availble for the question
		if ($choice[$i][0] != null)
		{
			$M = count($choice[$i]);
			for($j = 0; $j < $M; $j++)
			{
				echo $choice[$i][$j] . ": ". $answer[$i][$j]. "<br>";
			}
			for($j = 0; $j < count($narrative[$i]); $j++)
			{
				if($narrative[$i][$j] == '')
				{
				}else {
					echo "&nbsp&nbsp&nbsp&nbsp". $narrative[$i][$j]. "<br>";
				}
			}			
		}else {
			$L = count($answer[$i]);
			for($k = 0; $k < $L; $k++)
			{
				echo "&bull;".nl2br($answer[$i][$k]) . "<br>";
				if($narrative[$i][$k] == '')
				{
				}else {
					echo "&nbsp&nbsp&nbsp&nbsp". $narrative[$i][$k]. "<br>";
				}
			}
		}
	}
}
?>

</body>
</html>